package com.eeGroup.service;

import com.eeGroup.vo.User;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class LoginService {

    static Map<String,String> accounts = new HashMap<>();
    static {
        accounts.put("admin","112233");
        accounts.put("k11","112233");
        accounts.put("apple","112233");
    }


    public User login(String userName, String password) throws Exception{
        if(StringUtils.isEmpty(userName) || StringUtils.isEmpty(password)){
            throw new RuntimeException("账号密码不能为空！");
        }

        if(accounts.containsKey(userName) &&
                StringUtils.equalsIgnoreCase(accounts.get(userName), password)){
            User user = new User();
            user.setName(userName);
            user.setPwd(password);
            return user;
        }

        throw new RuntimeException("账号密码不符！");

    }
}
